<title>实验列表</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a><cite>实验列表</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">实验列表</div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="course-table-page" lay-filter="course-page"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="lineBar">
    <a class="layui-btn layui-btn-xs" lay-event="student_list">学生列表</a>
</script>

<script>
    layui.use(['jquery', 'table'], function(){
        var $ = layui.$, form = layui.form,
            table = layui.table, admin = layui.admin,
            view = layui.view;
        var width = window.screen.availWidth > 600 ? 600 : window.screen.availWidth;
        var i_container = layui.data('i_container');
        let course_id = i_container.experiment_course_id;
        var tablelns = table.render({
            elem: '#course-table-page'
            ,url: "/teacher/experiment"
            ,method: 'get'
            ,where: { courseID: course_id}
            ,cols: [[
                {field:'experimentName', title:'实验名', align:'center'}
                ,{field:'description', title:'实验描述', align:'center'}
                ,{field:'containerAliveTime',  title:'容器时长', align:'center', templet: function (d) {
                        return d.containerAliveTime + " 小时"
                    }}
                ,{field:'memoryLimit',  title:'内存限制', align:'center',templet: function (d) {
                        return d.memoryLimit + " MB"
                    }}
                ,{field:'cpuSetLimit',  title:'容器核数', align:'center',templet: function (d) {
                        return d.cpuSetLimit + " 核"
                    }}
                ,{field:'cpuShareLimit', title:'容器优先级', align:'center',templet: function (d) {
                        switch (d.cpuShareLimit) {
                            case 256:
                                return '极低';
                            case 512:
                                return '低';
                            case 1024:
                                return '正常';
                            case 2048:
                                return '高';
                            case 4096:
                                return '极高';
                        }
                        return '不明';
                    }}
                ,{field:'endTime',  title:'截止时间', align:'center', templet: function (d) {
                        return time(d.endTime);
                    }}
                ,{field:'imageID', title:'镜像ID', align:'center'}
                ,{align:'center',  title:'操作', toolbar:'#lineBar'}
            ]]
            ,parseData: function(res) {
                return {
                    "status": res.status,
                    "message": res.message,
                    "list": res.data,
                };
            }
            ,response: {
                statusName: 'status'
                ,statusCode: 200
                ,msgName: 'message'
                ,dataName: 'list'
            }
        });

        table.on('tool(course-page)', function (obj) {
            switch (obj.event) {
                case 'student_list':
                    layui.data('i_container', {
                        key: 'experiment_id'
                        ,value: obj.data.id
                    });
                    layui.data('i_container', {
                        key: 'course_id'
                        ,value: obj.data.courseID
                    });
                    location.hash = "/menu/experiment/studentInExperiment"
                    break;
            }
        });

    });

    function time(time = +new Date()) {
        var date = new Date(time + 8 * 3600 * 1000); // 增加8小时
        return date.toJSON().substr(0, 19).replace('T', ' ');
    }

    //显示结果
    function showMsg(text) {
        layer.msg("<div style=\"padding: 20px 100px;\">"+ text + "</div>", {
            time: 8000, //8s后自动关闭
            btn: ['明白了'],
            shade: 0.3,
            yes: function (index, layero) {
                layer.close(index);
            }
        });
    }
</script>